<!-- header -->
<template>
  <div class="header">
    <div class="l-content">
      <el-button @click="switchCollapse()">
        <el-icon>
          <component is="menu" />
        </el-icon>
      </el-button>

      <el-breadcrumb separator="/" class="bread">
        <el-breadcrumb-item
          v-for="item in breadcrumbList"
          :key="item.path"
          :to="getPath(item)"
        >
          <span>{{ item.meta.name }}</span>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown>
        <span class="el-dropdown-link">
          <img :src="getImgUrl('admin')" class="img" />
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleExit">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from "vue";
import { useAllDataStore } from "@/stores";
import { useRouter, useRoute } from "vue-router";
import type { RouteLocationMatched } from "vue-router";
const getImgUrl = (user: string) => {
  return new URL(`../assets/img/${user}.jpg`, import.meta.url).href;
};
const store = useAllDataStore();
const router = useRouter();
const route = useRoute();

/** 获取路由路径 */
const getPath = (item: any): string | Object => {
  if (!item) return "";
  return { path: item.redirect ? item.redirect : item.path };
};
/** 面包屑列表 */
const breadcrumbList = computed(() => route.matched);
const switchCollapse = () => {
  store.state.isCollapse = !store.state.isCollapse;
};
const handleExit = () => {
  store.clean();
  router.push("/");
};
</script>

<style scoped lang="less">
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 100%;
}
.l-content {
  display: flex;
  align-items: center;
  .el-button {
    margin-right: 20px;
  }
}
.r-content {
  .img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}
// :deep伪类选择器。具体功能如下：
// 使用:deep(.bread span)选择子组件中类名为bread下的所有span元素。
// 设置这些span元素的文本颜色为aliceblue，并且鼠标悬停时变为指针样式。
// !important确保这些样式优先级最高，不会被其他样式覆盖。
:deep(.bread span) {
  color: black !important;
  cursor: pointer !important;
}
</style>
